//
// Created by mio on 25-4-29.
//

#ifndef CONNECTIONMANAGER_H
#define CONNECTIONMANAGER_H

#include <unordered_map>
#include <memory>
#include <mutex>

#include "../Net/TcpConnection.h"

class ConnectionManager
{
public:
    ~ConnectionManager();
    static ConnectionManager* GetInstance();

public:
    void AddConn(const std::string& idefy, const TcpConnectionPtr conn);
    void RmvConn(const std::string& idefy);
    TcpConnectionPtr QueryConn(const std::string& idefy);

    uint32_t Size() const { return connMaps_.size(); }

private:
    ConnectionManager();

    void Close();
    std::mutex mtx_;
    static std::unique_ptr<ConnectionManager> instance_;
    std::unordered_map<std::string, TcpConnectionPtr> connMaps_;

};

#endif //CONNECTIONMANAGER_H